using System;
using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class ClockAItem : BaseItem
	{
		private float timer;

		private Transform hour;

		private Transform minute;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			hour = model.Find("Hour");
			minute = model.Find("Minute");
			UpdateTime(DateTime.Now.Hour % 12, DateTime.Now.Minute);
		}

		protected override void LateUpdate()
		{
			timer += Time.deltaTime;
			if (timer >= 60f)
			{
				timer = 0f;
				UpdateTime(DateTime.Now.Hour % 12, DateTime.Now.Minute);
			}
		}

		private void UpdateTime(float hourVal, float minuteVal)
		{
			minuteVal /= 60f;
			hourVal = (hourVal + minuteVal) / 12f;
			hour.localEulerAngles = new Vector3(0f, 0f, -360f * hourVal);
			minute.localEulerAngles = new Vector3(0f, 0f, -360f * minuteVal);
		}
	}
}
